package com.open.capacity.reimburse.task;


import com.open.capacity.reimburse.entity.SpringScheduledCron;
import com.open.capacity.reimburse.service.SpringScheduledCronService;
import com.open.capacity.utils.SpringUtil;

/**
 * @author yudong
 * @date 2019/5/11
 */
public interface ScheduledOfTask extends Runnable {

    /**
     * 定时任务方法
     */
    void execute();

    /**
     * 实现控制定时任务启用或禁用的功能
     */
    @Override
    default void run() {
        SpringScheduledCronService repository = SpringUtil.getBean(SpringScheduledCronService.class);
        SpringScheduledCron scheduledCron = repository.findByKey(this.getClass().getName());
        if (1 != scheduledCron.getStatus()) {
            return;
        }
        execute();
    }
}
